using System;
using System.Collections.Generic;
using System.Text;

namespace Weazel.Microblaze.Simulator.Components.Microblaze.Instructions
{
    public class Idiv : Instruction
    {
        private enum IdivInstructionKind
        {
            None,     // error
            idiv,     // divide rB by rA (signed)
            idivu     // divide rB by rA (unsigned)
        }

        private IdivInstructionKind kind;

        public override int CycleCount
        {
            get { return 1; }
        }

        public Idiv()
            : base("idiv")
        {
        }

        public override void Set(uint address, uint value)
        {
            base.Set(address, value);

            kind =
              (value & 0x2) == 0x00 ? IdivInstructionKind.idiv :
              IdivInstructionKind.idivu;
        }

        public override void Execute(MicroblazeComponent MicroblazeComponent)
        {
            throw new Exception("The method or operation is not implemented.");
        }

        public override string ToString()
        {
            return string.Format("{0} r{1}, r{2}, r{3}",
              kind,
              DestinationRegister,
              SourceRegisterA,
              SourceRegisterB
            );
        }
    }
}
